package org.example;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

// 游戏结束状态
public class GameOverState implements GameState {
    private final CodeRebirthGame game;

    public GameOverState(CodeRebirthGame game) {
        this.game = game;
    }

    @Override
    public void enter() {
        game.setLayout(new BorderLayout());
        game.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                game.changeState(new MainMenuState(game));
            }
        });
    }

    @Override
    public void render(Graphics g) {
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, game.getWidth(), game.getHeight());

        g.setColor(Color.RED);
        g.setFont(game.getResourceManager().getFont("title", 48f));

        String text = "系统被主神抓到正在被销毁";
        int textWidth = g.getFontMetrics().stringWidth(text);
        g.drawString(text, (game.getWidth()-textWidth)/2, game.getHeight()/2);
    }

    @Override public void update() {}
    @Override public void exit() { game.getContentPane().removeAll(); }
    @Override public void handleInput(KeyEvent e) {}
}
